package main

import (
	"fmt"
	"math/rand"
	"time"
)

func main() {
	//testMap1()
	//testMap2()
	//testMap3()
	//testMap4()
	//testMapFor()
	//testMap5()
	testDeleteKey()
}

func testMap1() {
	a := make(map[string]int)
	fmt.Printf("a = %v\n", a) //a = map[]
	a["a"] = 1
	a["b"] = 1
	fmt.Println(a) //map[a:1 b:1]
}

func testMap2() {
	var a map[string]int = map[string]int{
		"a": 1,
		"b": 2,
	}
	fmt.Println(a)
}

func testMap3() {
	var a map[string]int = map[string]int{
		"a": 1,
		"b": 2,
		"c": 3,
		"d": 4,
	}
	key := "a"
	fmt.Println(a[key])
}

func testMap4() {
	var a map[string]int = map[string]int{
		"a": 1,
		"b": 2,
		"c": 3,
		"d": 4,
	}
	key := "ad"
	var result int
	var ok bool
	result, ok = a[key]

	if ok == false {
		fmt.Println("no")
	} else {
		fmt.Println("yes")
	}
	fmt.Println(result)
	//fmt.Println(a[key])
}

func testMapFor() {
	var a map[string]int = map[string]int{
		"a": 1,
		"b": 2,
		"c": 3,
		"d": 4,
	}

	for key, value := range a {
		fmt.Println(key)
		fmt.Println(value)
	}
}

func testMap5() {
	rand.Seed(time.Now().UnixNano())
	var a map[int]int = make(map[int]int, 1024)

	for i := 0; i < 100; i++ {
		key := i
		value := rand.Intn(1000)
		a[key] = value
		fmt.Printf("key = %v value = %v\n", key, value)
	}
	fmt.Printf("a = %v", a)

	for key, value := range a {
		fmt.Printf("key = %v value = %v\n", key, value)
	}
}

func testDeleteKey() {
	rand.Seed(time.Now().UnixNano())
	var a map[int]int = make(map[int]int, 1024)

	for i := 0; i < 100; i++ {
		key := i
		value := rand.Intn(1000)
		a[key] = value
	}
	fmt.Printf("a = %v\n", a)
	delete(a, 1)
	fmt.Printf("a = %v\n", a)
}
